
/************************************************************************
*
*
*       			FileName:./header/listenThread.h
*
*         			Author.wzj
*
*       			Email:345517039@qq.com
*
*      	    		Create:2017-08-09 22:23:50
*
*      		    	Description:-
*
*
*************************************************************************/


#ifndef __LISTENTHREAD_H__
#define __LISTENTHREAD_H__

#include "define.h"
#include "thread.h"
#include "ioManager.h"
#include "log.h"

extern confMgr *conf;

/*@brief: 监听线程的上下文;
 *
 */
struct listenThread_ctx{
	struct pthread_ctx  pth;
	struct socket_st *head;
	ioModel *io;
	int ioType; //iotype;
	size_t uListenSocketCount;
	size_t currentIndex;
	std::vector<int> socketqueue; //与工作线程交互的本地套接字;
	bool bStopFlag;
	int logfd; //和日志线程交互的套接字;
	char *logbuf; //日志缓冲区;
	int bufSize; //日志缓冲区的大小;
};


/**
 * @brief 监听线程类;
 */
class ListenThread:public thread
{	
	public:
		ListenThread();
		~ListenThread();
		static void * listenThreadRun(void * arg);
		struct listenThread_ctx & getListenThreadOpt();
		int init(void *arg); //
		int handleEventForIo(int count); 
		int WaitEventForIo(int type);
		void displayLisSocketOpt();
	private:
		int readConf(); //读取配置;
		struct listenThread_ctx  lis;
		struct server_conf_st serconf;
		MemPool mem;
};




/**
 * @brief 
 */
inline void ListenThread::displayLisSocketOpt()
{
	if (lis.socketqueue.size()!= 0)
	{
		std::vector<int>::iterator it = lis.socketqueue.begin();
		for(; it != lis.socketqueue.end(); it++)
		{
			std::cout << *it << std::endl;
		}
	}else{
		std::cout << "socketqueue is empty!" << std::endl;
	}
}



/**
 * @brief 
 *
 * @return 
 */
inline struct listenThread_ctx & ListenThread::getListenThreadOpt(){
	return this->lis;
}





















#endif 

